#pragma  once
#include "GUIManager.h"
#include <CEGUI.h>
#ifdef TARGET_DX11
#include <RendererModules\Direct3D11\CEGUIDirect3D11Renderer.h>
namespace Graphics{ 
	typedef CEGUI::Direct3D11Renderer* CEGUIRendererPtr;
	typedef CEGUI::Direct3D11Renderer CEGUIRenderer;
}
#elif defined(TARGET_DX10)
#include <RendererModules\Direct3D11\CEGUIDirect3D10Renderer.h>
namespace Graphics{ 
	typedef CEGUI::Direct3D10Renderer* CEGUIRendererPtr;
	typedef CEGUI::Direct3D10Renderer CEGUIRenderer;
}
#elif defined(TARGET_DX9)
#include <RendererModules\Direct3D11\CEGUIDirect3D9Renderer.h>
namespace Graphics{ 
	typedef CEGUI::Direct3D9Renderer* CEGUIRendererPtr;
	typedef CEGUI::Direct3D9Renderer CEGUIRenderer;
}
#endif

namespace Graphics{
	class CEGUIManager : public GUIManager{
	public:
		CEGUIManager();
		~CEGUIManager();

		void initializeManager(RenderContextPtr context);
		void render(RenderContextPtr context);
		void injectKeyInput(Input::KeyDefinition key, bool down);
		void injectMouseInput(float x,float y);
		void showCursor(bool var);
		void showGUI(bool var);

		// Window functions
		bool getVisible(std::string name);
		void setVisible(std::string name, bool var);
		void setText(std::string name, std::string text);

		// List functions
		void clearList(std::string listBox);
		void addListBoxItem(std::string listBox, std::string itemName);
		void removeListBoxItem(std::string listBox, std::string itemName);
		std::string getSelectedItemFromList(std::string listName);

		void subscribeToButtonClick(std::string buttonName, boost::function<void(void)> func);
	private:
		void updateListBoxes();
		void updateButtonSubscriptions();
		void injectInput(float dt);

		bool buttonClickCallback(const CEGUI::EventArgs& args);

		CEGUIRendererPtr m_renderer;
		
		std::vector<std::pair<bool,std::pair<std::string,std::string>>> m_listBoxes;
		std::vector<std::pair<std::string,boost::function<void(void)>>> m_buttonFunctions;

		std::map<std::string,boost::function<void(void)>> m_buttonMapping;
		std::map<std::string,CEGUI::Event::Connection> m_eventConnections;

		MutexPtr	m_listBoxesMutex,
					m_buttonMutex;
		CEGUI::Font* m_listBoxFont;
	};
}